// pages/list3/list3.js
const app = getApp()
var landui = require("../../utils/util.js");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    domain: app.globalData.domain,
    trueDomain: app.globalData.trueDomain,
    current_nav: 'index',
    list2: [],
    url: '/pages/interview/detail',
    msg: '上拉加载更多~',
    current_page: 1,
    per_page: 7,
    total_pages: 1,
  },

  // 首页接口
  /**
   * 今日推荐    https://ynjksh.cn/api/articles?page=1&number=6&isAids=1&type=special
   * 健康专访    https://ynjksh.cn/api/audios?type=hot&include=expert&number=4&isAids=1
   * 视频天地    https://ynjksh.cn/api/videos?page=2&number=2&isAids=1
   * 图文库      https://ynjksh.cn/api/articles?page=1&number=6&type=image&isAids=1
   * 活动专区    https://ynjksh.cn/api/articles?page=1&number=6&isAids=1&type=special
   */
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // https://ynjksh.cn/api/audios?type=hot&include=expert&number=4&isAids=1
    landui.common.post({
      module: 'audios',
      param:{type:'hot',include:'expert',page:1, number:7,isAids:1},
      success: function (res) {
        console.log(res.data);
        if (res.meta.pagination.total_pages == 1) {
          that.msg = '已经到底啦~'
        } else {
          //that.data.current_page = res.meta.pagination.current_page + 1;
          that.data.total_pages = res.meta.pagination.total_pages
        }
        //console.log(that.data.current_page);
        //console.log(that.data.total_pages);
       
        that.setData({
          list2: res.data,
          msg: that.msg,
          current_page: that.data.current_page + 1,
          total_pages: res.meta.pagination.total_pages,
        })
      },
      fail: function () {
      }
    })
  },
  



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
  
    if (that.data.current_page + 1 <= that.data.total_pages) {
      landui.common.post({
        module: 'audios',
        param: {page:that.data.current_page, type: 'hot', include: 'expert', number: 7, isAids: 1 },
        success: function (res) {
          that.setData({
            list2: that.data.list2.concat(res.data),
            current_page: that.data.current_page + 1,
            total_pages: res.meta.pagination.total_pages,
          })
        },
        fail: function () { }
      });
    } else {
      that.setData({
        msg: '已经到底啦~'
      })
    }
  },
})